<template>
  <div class="wrap">
    <div class="box">
      <Image height="254" name="account_review" oss type="png" width="502" />
      <div class="prm_title">系统正在加急审核中</div>
      <div class="prm_time">
        预计<span style="color:#ff8002">1分钟内</span>完成审核请耐心等待~
      </div>
      <div class="prm_time mt20" @tap="DrRef.change()">
        您还需要签署一份合作申请书即可完成合作
      </div>
    </div>
  </div>
  <!-- 审核状态 -->
  <Popup ref="DrRef">
    <div class="check_status">
      <Image :name="`status_icon/${status === 2 ? 'success' : 'error'}`" oss size="112" type="png" />
      <div :style="{color: status === 2 ? '#2DC76D' : '#FF4D4F'}" class="title">{{ status === 2 ? '审核成功': '审核失败' }}</div>
      <div class="content">
        即将{{ status === 2 ? '跳转签署合作申请书': '返回资料完善页面' }}
      </div>
    </div>
  </Popup>
</template>

<script lang="ts" setup>
import Image from '@C/Image.vue'
import Popup from '@C/Popup.vue'
import { ref } from 'vue'
import { Router, onUnload } from '@U/common'
import { loginOK } from '@U/Auth'
import { getProfileStatus } from './request'

const DrRef = ref()
const status = ref(<null | number>null)
const checkTimer = setInterval(async () => {
  const res = await getProfileStatus().finally(() => {})
  if (res?.code === 200) {
    const { profileStatus, contractStatus } = { ...res.data }
    status.value = profileStatus
    if (profileStatus === 2) {
      if (contractStatus === 0 || contractStatus === 2) {
        clearInterval(checkTimer)
        DrRef.value?.change()
        setTimeout(() => {
          if (contractStatus === 0) Router.reLaunch('signContract')
          if (contractStatus === 2) loginOK()
        }, 2000)
      }
    }
    if (profileStatus === 3) {
      clearInterval(checkTimer)
      DrRef.value?.change()
      setTimeout(() => {
        uni.$emit('getDefForm') // 触发全局事件getDefForm
        Router.back()
      }, 2000)
    }
    // 通过 / 驳回
    // if (status.value === 2 || status.value === 3) {
    //   DrRef.value?.change()
    //   // 跳转
    //   setTimeout(async () => {
    //     clearInterval(checkTimer)
    //     if (status.value === 2) {
    //       if (data.contractStatus === 0) {
    //         Router.reLaunch('signContract')
    //       } else if (data.contractStatus === 2) {
    //         Router.reLaunch('workbench')
    //       }
    //     }
    //     if (status.value === 3) {
    //       uni.$emit('getDefForm') // 触发全局事件getDefForm
    //       Router.back()
    //     }
    //   }, 3000)
    // }
  }
}, 5000)
onUnload(() => {
  clearInterval(checkTimer)
  uni.$off('getDefForm')
})
</script>

<style lang="less" scoped>
.wrap {
  display: flex;
  justify-content: center;
  .box {
    margin-top: 284rpx;
    .prm_title {
      margin: 20rpx 0;
      text-align: center;
    }
    .prm_time {
      text-align: center;
    }
  }
}
.check_status {
  width: 520rpx;
  height: 360rpx;
  background: white;
  border-radius: 48rpx;
  padding: 40rpx 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  .title {
    font-size: 36rpx;
    margin: 40rpx 0 32rpx;
  }
  .content {
    font-size: 32rpx;
  }
}
</style>
